<template>
  <div>
    <div class="top">
      <van-icon @click="goback" class="zuo" name="arrow-left" />
      修改密码
    </div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="oldpass"
        name="原密码"
        label="原密码"
        placeholder="原密码"
        :rules="[{ required: true, message: '请填写原密码' }]"
      />
      <van-field
        v-model="newpass"
        type="password"
        name="新密码"
        label="新密码"
        placeholder="新密码"
        :rules="[{ required: true, message: '请填写新密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
import { setpass } from '@/api/login';
export default {
  data() {
    return {
      oldpass: "Hyr123456",
      newpass: "Hyr654321",
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      let userid=localStorage.getItem("userid")
      console.log(userid,this.oldpass,this.newpass);
      setpass({userid:localStorage.getItem("userid"),oldpassword:this.oldpass,newpassword:this.newpass}).then((res)=>{
        Toast("修改成功,请重新登陆");
        localStorage.clear()
        setTimeout(()=>{
            this.$router.push("/Login")
        },500)
      })
    },
    goback() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
.top {
  width: 100%;
  height: 3.125rem;
  font-size: 1.25rem;
  text-align: center;
  line-height: 3.125rem;
  /* border-bottom: 0.0625rem solid black; */
  position: relative;
}
.zuo {
  position: absolute;
  left: 0.625rem;
  font-size: 1.25rem;
  top: 0.9375rem;
}
</style>